<?php
class handle_route
{			
	public $_seokey = array();
	public function rt_get_route($route='route')
	{	
		$str_seo = (empty($_GET[$route])) ? '' : $_GET[$route];
		if(empty($str_seo))
		{
			$str_seo = (empty($_POST[$route])) ? '' : $_POST[$route];
		}
		$str_seo_key = strtolower($str_seo);
		return $str_seo_key;
	}
	
	/*
    NULL : $type;
    $type : no $type;
    */
	public function rt_get_all_val_seo($route='route')
	{
		$arr = array();
		$arrR = explode('/', $this->rt_get_route($route));
		foreach($arrR as $val)
		{
			if(!empty($val) || $val==0)
			{
				$arr[] = strtolower($val);
			}
		} 
		return $arr;
	}
    /**
	* $action ten action chinh la ten ham
	* tra ve seokey cua action
	*/
    public function rt_get_seokey_act($action)
    {
        $model = new system_model();
        $result = $model->model_get_seokey_act($action);
        return isset($result['SeoKey'])?$result['SeoKey']:NULL;
    }
	/**
	* $com ten com chinh la ten class
	* tra ve seokey cua components
	*/
	public function rt_get_seokey_com($com)
    {
        $model = new system_model();
        $result = $model->model_get_seokey_com($com);
        return isset($result['SeoKey'])?$result['SeoKey']:NULL;
    }
    
    public function rt_create_link($app='admin', $id_cat=NULL, $action=NUll)
    {
        $url = '';
        $url[] = URL_BASE;
        $url[] = $app;
        
        $model = new system_model();
        if($id_cat != NULL)
        {
            $get_seokey = $model->model_get_seokey_catid($id_cat);
            if(!empty($get_seokey))
            {
                $url[] = $get_seokey['SeoKey'];    
            }
            
        }
        if($action != NULL)
        {
            $get_seokey = $model->model_get_seokey_act($action);
            if(!empty($get_seokey))
            {
                $url[] = $get_seokey['SeoKey'];
            }
        }
        return implode('/', $url) . '/';
    }
    
}
?>
